home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 44 / PC Actual CD 44.iso / Linux / Cygwin / full.exe / Disk1 / data1.cab / Tools / H-i586-cygwin32 / i586-cygwin32 / include / Windows32 / Sockets.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-04  |  32.1 KB  |  1,050 lines

  1. /* 
  2.    Sockets.h
  3.  
  4.    Windows Sockets specification version 1.1
  5.  
  6.    Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
  7.    Thanks to Linux header files for supplying many needed definitions
  8.  
  9.    Author:  Scott Christley <scottc@net-community.com>
  10.    Date: 1996
  11.    
  12.    This file is part of the Windows32 API Library.
  13.  
  14.    This library is free software; you can redistribute it and/or
  15.    modify it under the terms of the GNU Library General Public
  16.    License as published by the Free Software Foundation; either
  17.    version 2 of the License, or (at your option) any later version.
  18.    
  19.    This library is distributed in the hope that it will be useful,
  20.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  22.    Library General Public License for more details.
  23.  
  24.    If you are interested in a warranty or support for this source code,
  25.    contact Scott Christley <scottc@net-community.com> for more information.
  26.    
  27.    You should have received a copy of the GNU Library General Public
  28.    License along with this library; see the file COPYING.LIB.
  29.    If not, write to the Free Software Foundation, 
  30.    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  31. */ 
  32.  
  33. /*-
  34.  * Portions Copyright (c) 1980, 1983, 1988, 1993
  35.  *     The Regents of the University of California.  All rights reserved.
  36.  *
  37.  * Redistribution and use in source and binary forms, with or without
  38.  * modification, are permitted provided that the following conditions
  39.  * are met:
  40.  * 1. Redistributions of source code must retain the above copyright
  41.  *    notice, this list of conditions and the following disclaimer.
  42.  * 2. Redistributions in binary form must reproduce the above copyright
  43.  *    notice, this list of conditions and the following disclaimer in the
  44.  *    documentation and/or other materials provided with the distribution.
  45.  * 3. All advertising materials mentioning features or use of this software
  46.  *    must display the following acknowledgement:
  47.  *    This product includes software developed by the University of
  48.  *    California, Berkeley and its contributors.
  49.  * 4. Neither the name of the University nor the names of its contributors
  50.  *    may be used to endorse or promote products derived from this software
  51.  *    without specific prior written permission.
  52.  *
  53.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  54.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  55.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  56.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  57.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  58.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  59.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  60.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  61.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  62.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  63.  * SUCH DAMAGE.
  64.  *
  65.  * -
  66.  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
  67.  *
  68.  * Permission to use, copy, modify and distribute this software for any
  69.  * purpose with or without fee is hereby granted, provided that the above
  70.  * copyright notice and this permission notice appear in all copies, and that
  71.  * the name of Digital Equipment Corporation not be used in advertising or
  72.  * publicity pertaining to distribution of the document or software without
  73.  * specific, written prior permission.
  74.  *
  75.  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
  76.  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
  77.  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
  78.  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  79.  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  80.  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  81.  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  82.  * SOFTWARE.
  83.  * -
  84.  * --Copyright--
  85.  */
  86.  
  87. #ifndef _GNU_H_WINDOWS32_SOCKETS
  88. #define _GNU_H_WINDOWS32_SOCKETS
  89.  
  90. #ifdef __cplusplus
  91. extern "C" {
  92. #endif /* __cplusplus */
  93.  
  94. /* Skip if invoked by resource compiler */
  95. #ifndef    RC_INVOKED
  96.  
  97. /* BSD */
  98. #ifndef _SYS_TYPES_H
  99. typedef unsigned char   u_char;
  100. typedef unsigned short  u_short;
  101. typedef unsigned int    u_int;
  102. typedef unsigned long   u_long;
  103. #endif
  104.  
  105. #endif    /* RC_INVOKED */
  106.  
  107. /*
  108.   Default maximium number of sockets.
  109.   Define this before including Sockets.h to increase; this does not
  110.   mean that the underlying Windows Sockets implementation has to
  111.   support that many!
  112.   */
  113. #ifndef FD_SETSIZE
  114. #define FD_SETSIZE      64
  115. #endif /* !FD_SETSIZE */
  116.  
  117. /*
  118.   These macros are critical to the usage of Windows Sockets.
  119.   According to the documentation, a SOCKET is no longer represented
  120.   by a "small non-negative integer"; so all programs MUST use these
  121.   macros for setting, initializing, clearing and checking the
  122.   fd_set structures.
  123.   */
  124.  
  125. #ifndef    RC_INVOKED
  126.  
  127. typedef u_int           SOCKET;
  128.  
  129. #ifndef __INSIDE_CYGWIN__
  130. /* fd_set may have been defined by the newlib <sys/types.h>.  */
  131. #ifdef fd_set
  132. #undef fd_set
  133. #endif
  134. typedef struct fd_set {
  135.         u_int   fd_count;
  136.         SOCKET  fd_array[FD_SETSIZE];
  137. } fd_set;
  138.  
  139. /* Internal function, not documented except in winsock.h */
  140. extern int PASCAL __WSAFDIsSet(SOCKET, fd_set*);
  141.  
  142. #ifdef FD_CLR
  143. #undef FD_CLR
  144. #endif
  145. #define FD_CLR(fd, set) do { \
  146.     u_int __i; \
  147.     for (__i = 0; __i < ((fd_set*)(set))->fd_count ; __i++) { \
  148.         if (((fd_set*)(set))->fd_array[__i] == fd) { \
  149.             while (__i < ((fd_set*)(set))->fd_count-1) { \
  150.                 ((fd_set*)(set))->fd_array[__i] = \
  151.                     ((fd_set*)(set))->fd_array[__i+1]; \
  152.                 __i++; \
  153.             } \
  154.             ((fd_set*)(set))->fd_count--; \
  155.             break; \
  156.         } \
  157.     } \
  158. } while(0)
  159.  
  160. #ifdef FD_SET
  161. #undef FD_SET
  162. #endif
  163. #define FD_SET(fd, set) do { \
  164.     if (((fd_set*)(set))->fd_count < FD_SETSIZE) \
  165.         ((fd_set*)(set))->fd_array[((fd_set*)(set))->fd_count++]=(fd);\
  166. } while(0)
  167.  
  168. #ifdef FD_ZERO
  169. #undef FD_ZERO
  170. #endif
  171. #define FD_ZERO(set) (((fd_set*)(set))->fd_count=0)
  172.  
  173. #ifdef FD_ISSET
  174. #undef FD_ISSET
  175. #endif
  176. #define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (fd_set*)(set))
  177.  
  178. /*
  179.   time structures
  180.   */
  181. struct timeval {
  182.   long tv_sec;     /* seconds */
  183.   long tv_usec;    /* microseconds */
  184. };
  185.  
  186. #ifndef __MINGW32__
  187. struct timezone {
  188.   int tz_minuteswest; /* minutes west of Greenwich */
  189.   int tz_dsttime;     /* type of dst correction */
  190. };
  191. #endif
  192.  
  193. #endif /* ndef __INSIDE_CYGWIN__ */
  194.  
  195. /*
  196.  Operations on timevals.
  197.  
  198.  NB: timercmp does not work for >= or <=.
  199.  */
  200. #define    timerisset(tvp)        ((tvp)->tv_sec || (tvp)->tv_usec)
  201. #define    timercmp(tvp, uvp, cmp)    \
  202.     (((tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec) \
  203.     || (tvp)->tv_sec cmp (uvp)->tv_sec)
  204. #define    timerclear(tvp)        ((tvp)->tv_sec = (tvp)->tv_usec = 0)
  205.  
  206. #endif    /* RC_INVOKED */
  207.  
  208. /*
  209.   ioctl command encoding.
  210.   Some of this is different than what Linux has
  211.   */
  212. #define IOCPARM_MASK    0x7f
  213. #define IOC_VOID        0x20000000
  214. #define IOC_OUT         0x40000000
  215. #define IOC_IN          0x80000000
  216. #define IOC_INOUT       (IOC_IN | IOC_OUT)
  217.  
  218. #ifndef __INSIDE_CYGWIN__
  219. /* _IO(magic, subcode) */
  220. #define _IO(c,d)        (IOC_VOID | ((c)<<8) | (d))
  221. /* _IOXX(magic, subcode, arg_t) */
  222. #define _IOW(c,d,t)     (IOC_IN | (((long)sizeof(t) & IOCPARM_MASK)<<16) | \
  223.              ((c)<<8) | (d))
  224. #define _IOR(c,d,t)     (IOC_OUT | (((long)sizeof(t) & IOCPARM_MASK)<<16) | \
  225.              ((c)<<8) | (d))
  226. #endif /* ndef __INSIDE_CYGWIN__ */
  227.  
  228. /*
  229.   This stuff is hard-coded on Linux
  230.   But winsock.h uses the macros defined above
  231.   */
  232. #define FIONREAD    _IOR('f', 127, u_long)
  233. #ifndef __INSIDE_CYGWIN__
  234. #define FIONBIO     _IOW('f', 126, u_long)
  235. #endif
  236. #define FIOASYNC    _IOW('f', 125, u_long)
  237.  
  238. #define SIOCSHIWAT  _IOW('s',  0, u_long)
  239. #define SIOCGHIWAT  _IOR('s',  1, u_long)
  240. #define SIOCSLOWAT  _IOW('s',  2, u_long)
  241. #define SIOCGLOWAT  _IOR('s',  3, u_long)
  242. #define SIOCATMARK  _IOR('s',  7, u_long)
  243.  
  244. /*
  245.  Structures returned by network data base library, taken from the
  246.  BSD file netdb.h.  All addresses are supplied in host order, and
  247.  returned in network order (suitable for use in system calls).
  248.  
  249.  Slight modifications for differences between Linux and winsock.h
  250.  */
  251.  
  252. #ifndef    RC_INVOKED
  253. #ifndef __INSIDE_CYGWIN__
  254. struct  hostent {
  255.   char    *h_name;                /* official name of host */
  256.   char    **h_aliases;            /* alias list */
  257.   short   h_addrtype;             /* host address type */
  258.   short   h_length;               /* length of address */
  259.   char    **h_addr_list;          /* list of addresses */
  260. #define h_addr  h_addr_list[0]    /* address, for backward compat */
  261. };
  262.  
  263. /*
  264.  * Assumption here is that a network number
  265.  * fits in an unsigned long -- someday that won't be true!
  266.  */
  267. struct  netent {
  268.   char    *n_name;      /* official name of net */
  269.   char    **n_aliases;  /* alias list */
  270.   short   n_addrtype;   /* net address type */
  271.   u_long  n_net;        /* network # */
  272. };
  273.  
  274. struct  servent {
  275.   char    *s_name;      /* official service name */
  276.   char    **s_aliases;  /* alias list */
  277.   short   s_port;       /* port # */
  278.   char    *s_proto;     /* protocol to use */
  279. };
  280.  
  281. struct  protoent {
  282.   char    *p_name;      /* official protocol name */
  283.   char    **p_aliases;  /* alias list */
  284.   short   p_proto;      /* protocol # */
  285. };
  286. #endif /* ndef __INSIDE_CYGWIN__ */
  287.  
  288. /*
  289.   Standard well-known IP protocols.
  290.   For some reason there are differences between Linx and winsock.h
  291.   */
  292. enum {
  293.   IPPROTO_IP = 0,
  294.   IPPROTO_ICMP = 1,
  295.   IPPROTO_GGP = 2,               /* huh? */
  296.   IPPROTO_IPIP = 4,
  297.   IPPROTO_TCP = 6,               /* Transmission Control Protocol */
  298.   IPPROTO_EGP = 8,
  299.   IPPROTO_PUP = 12,
  300.   IPPROTO_UDP = 17,              /* User Datagram Protocol */
  301.   IPPROTO_IDP = 22,
  302.   IPPROTO_ND = 77,               /* This one was in winsock.h */
  303.  
  304.   IPPROTO_RAW = 255,             /* raw IP packets */
  305.   IPPROTO_MAX = 256
  306. };
  307.  
  308. /* Standard well-known ports */
  309. enum {
  310.   IPPORT_ECHO = 7,
  311.   IPPORT_DISCARD = 9,
  312.   IPPORT_SYSTAT = 11,
  313.   IPPORT_DAYTIME = 13,
  314.   IPPORT_NETSTAT = 15,
  315.   IPPORT_FTP = 21,
  316.   IPPORT_TELNET = 23,
  317.   IPPORT_SMTP = 25,
  318.   IPPORT_TIMESERVER = 37,
  319.   IPPORT_NAMESERVER = 42,
  320.   IPPORT_WHOIS = 43,
  321.   IPPORT_MTP = 57,
  322.  
  323.   IPPORT_TFTP = 69,
  324.   IPPORT_RJE = 77,
  325.   IPPORT_FINGER = 79,
  326.   IPPORT_TTYLINK = 87,
  327.   IPPORT_SUPDUP = 95,
  328.  
  329.   IPPORT_EXECSERVER = 512,
  330.   IPPORT_LOGINSERVER = 513,
  331.   IPPORT_CMDSERVER = 514,
  332.   IPPORT_EFSSERVER = 520,
  333.  
  334.   /* UDP ports. */
  335.   IPPORT_BIFFUDP = 512,
  336.   IPPORT_WHOSERVER = 513,
  337.   IPPORT_ROUTESERVER = 520,
  338.  
  339.   /* Ports less than this value are reservered for privileged processes. */
  340.   IPPORT_RESERVED = 1024,
  341.  
  342.   /* Ports greater than this value are reserved for 
  343.      (non-privileged) processes */
  344.   IPPORT_USERRESERVED = 5000
  345. };
  346.  
  347. #endif    /* RC_INVOKED */
  348.  
  349.  
  350. /* Link numbers. */
  351. #define IMPLINK_IP              155
  352. #define IMPLINK_LOWEXPER        156
  353. #define IMPLINK_HIGHEXPER       158
  354.  
  355. #ifndef RC_INVOKED
  356.  
  357. /* Linux uses a simple unsigned long int, but winsock.h ... */
  358. struct in_addr {
  359.         union {
  360.                 struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
  361.                 struct { u_short s_w1,s_w2; } S_un_w;
  362.                 u_long S_addr;
  363.         } S_un;
  364. #define s_addr  S_un.S_addr
  365. #define s_host  S_un.S_un_b.s_b2
  366. #define s_net   S_un.S_un_b.s_b1
  367. #define s_imp   S_un.S_un_w.s_w2
  368. #define s_impno S_un.S_un_b.s_b4
  369. #define s_lh    S_un.S_un_b.s_b3
  370. };
  371.  
  372. #endif    /* RC_INVOKED */
  373.  
  374. /*
  375.  Definitions of bits in internet address integers.
  376.  On subnets, host and network parts are found according
  377.  to the subnet mask, not these masks.
  378.  */
  379. #define IN_CLASSA(i)            (((long)(i) & 0x80000000) == 0)
  380. #define IN_CLASSA_NET           0xff000000
  381. #define IN_CLASSA_NSHIFT        24
  382. #define IN_CLASSA_HOST          0x00ffffff
  383. #define IN_CLASSA_MAX           128
  384.  
  385. #define IN_CLASSB(i)            (((long)(i) & 0xc0000000) == 0x80000000)
  386. #define IN_CLASSB_NET           0xffff0000
  387. #define IN_CLASSB_NSHIFT        16
  388. #define IN_CLASSB_HOST          0x0000ffff
  389. #define IN_CLASSB_MAX           65536
  390.  
  391. #define IN_CLASSC(i)            (((long)(i) & 0xe0000000) == 0xc0000000)
  392. #define IN_CLASSC_NET           0xffffff00
  393. #define IN_CLASSC_NSHIFT        8
  394. #define IN_CLASSC_HOST          0x000000ff
  395.  
  396. #define INADDR_ANY              (u_long)0x00000000
  397. #define INADDR_LOOPBACK         0x7f000001
  398. #define INADDR_BROADCAST        (u_long)0xffffffff    
  399. #define INADDR_NONE             0xffffffff
  400.  
  401.  
  402. #ifndef RC_INVOKED
  403.  
  404. /*
  405.  Structure describing an Internet (IP) socket address.
  406.  */
  407. struct sockaddr_in {
  408.   short   sin_family;
  409.   u_short sin_port;
  410.   struct  in_addr sin_addr;
  411.   char    sin_zero[8];
  412. };
  413.  
  414. #endif    /* RC_INVOKED */
  415.  
  416. /*
  417.   EVERYTHING FROM THIS POINT IS MAINLY SPECIFIC TO Win32
  418.  
  419.   Structure which holds the detail for the underlying Window Sockets
  420.   implementation.  Set when WSAStartup() is called.
  421.   */
  422. #define WSADESCRIPTION_LEN      256
  423. #define WSASYS_STATUS_LEN       128
  424.  
  425. #ifndef    RC_INVOKED
  426.  
  427. typedef struct WSAData {
  428.   WORD wVersion;
  429.   WORD wHighVersion;
  430.   char szDescription[WSADESCRIPTION_LEN+1];
  431.   char szSystemStatus[WSASYS_STATUS_LEN+1];
  432.   unsigned short iMaxSockets;
  433.   unsigned short iMaxUdpDg;
  434.   char *lpVendorInfo;
  435. } WSADATA, *LPWSADATA;
  436.  
  437. #endif    /* RC_INVOKED */
  438.  
  439. #ifndef __INSIDE_CYGWIN__
  440. #define IP_OPTIONS          1
  441. #endif
  442.  
  443. #define IP_MULTICAST_IF     2
  444. #define IP_MULTICAST_TTL    3
  445. #define IP_MULTICAST_LOOP   4
  446. #define IP_ADD_MEMBERSHIP   5
  447. #define IP_DROP_MEMBERSHIP  6
  448.  
  449. #define IP_DEFAULT_MULTICAST_TTL   1
  450. #define IP_DEFAULT_MULTICAST_LOOP  1
  451. #define IP_MAX_MEMBERSHIPS         20
  452.  
  453. #ifndef    RC_INVOKED
  454.  
  455. struct ip_mreq {
  456.   struct in_addr imr_multiaddr;
  457.   struct in_addr imr_interface;
  458. };
  459.  
  460. #endif    /* RC_INVOKED */
  461.  
  462. /*
  463.  * Definitions related to sockets: types, address families, options,
  464.  * taken from the BSD file sys/socket.h.
  465.  */
  466.  
  467. /*
  468.  * This is used instead of -1, since the
  469.  * SOCKET type is unsigned.
  470.  */
  471. #define INVALID_SOCKET  (SOCKET)(~0)
  472. #define SOCKET_ERROR            (-1)
  473.  
  474. /* Socket types. */
  475. #define SOCK_STREAM     1
  476. #define SOCK_DGRAM      2
  477. #define SOCK_RAW        3
  478. #define SOCK_RDM        4 
  479. #define SOCK_SEQPACKET  5
  480.  
  481. #ifndef __INSIDE_CYGWIN__
  482. /* For setsockoptions(2) */
  483. #define SO_DEBUG        0x0001
  484. #define SO_ACCEPTCONN   0x0002
  485. #define SO_REUSEADDR    0x0004
  486. #define SO_KEEPALIVE    0x0008
  487. #define SO_DONTROUTE    0x0010
  488. #define SO_BROADCAST    0x0020
  489. #define SO_USELOOPBACK  0x0040
  490. #define SO_LINGER       0x0080
  491. #define SO_OOBINLINE    0x0100
  492.  
  493. #define SO_DONTLINGER   (u_int)(~SO_LINGER)
  494.  
  495. /*
  496.  * Additional options.
  497.  */
  498. #define SO_SNDBUF       0x1001          /* send buffer size */
  499. #define SO_RCVBUF       0x1002          /* receive buffer size */
  500. #define SO_SNDLOWAT     0x1003          /* send low-water mark */
  501. #define SO_RCVLOWAT     0x1004          /* receive low-water mark */
  502. #define SO_SNDTIMEO     0x1005          /* send timeout */
  503. #define SO_RCVTIMEO     0x1006          /* receive timeout */
  504. #define SO_ERROR        0x1007          /* get error status and clear */
  505. #define SO_TYPE         0x1008          /* get socket type */
  506.  
  507. /*
  508.  * Options for connect and disconnect data and options.  Used only by
  509.  * non-TCP/IP transports such as DECNet, OSI TP4, etc.
  510.  */
  511. #define SO_CONNDATA     0x7000
  512. #define SO_CONNOPT      0x7001
  513. #define SO_DISCDATA     0x7002
  514. #define SO_DISCOPT      0x7003
  515. #define SO_CONNDATALEN  0x7004
  516. #define SO_CONNOPTLEN   0x7005
  517. #define SO_DISCDATALEN  0x7006
  518. #define SO_DISCOPTLEN   0x7007
  519.  
  520. /*
  521.  * Option for opening sockets for synchronous access.
  522.  */
  523. #define SO_OPENTYPE     0x7008
  524.  
  525. #define SO_SYNCHRONOUS_ALERT    0x10
  526. #define SO_SYNCHRONOUS_NONALERT 0x20
  527.  
  528. /*
  529.  * Other NT-specific options.
  530.  */
  531. #define SO_MAXDG        0x7009
  532. #define SO_MAXPATHDG    0x700A
  533. #endif /* ndef __INSIDE_CYGWIN__ */
  534.  
  535. /*
  536.  * TCP options.
  537.  */
  538. #define TCP_NODELAY     0x0001
  539. #define TCP_BSDURGENT   0x7000
  540.  
  541. /*
  542.  * Address families.
  543.  */
  544. #define AF_UNSPEC       0               /* unspecified */
  545. #define AF_UNIX         1               /* local to host (pipes, portals) */
  546. #define AF_INET         2               /* internetwork: UDP, TCP, etc. */
  547. #define AF_IMPLINK      3               /* arpanet imp addresses */
  548. #define AF_PUP          4               /* pup protocols: e.g. BSP */
  549. #define AF_CHAOS        5               /* mit CHAOS protocols */
  550. #define AF_IPX          6               /* IPX and SPX */
  551. #define AF_NS           6               /* XEROX NS protocols */
  552. #define AF_ISO          7               /* ISO protocols */
  553. #define AF_OSI          AF_ISO          /* OSI is ISO */
  554. #define AF_ECMA         8               /* european computer manufacturers */
  555. #define AF_DATAKIT      9               /* datakit protocols */
  556. #define AF_CCITT        10              /* CCITT protocols, X.25 etc */
  557. #define AF_SNA          11              /* IBM SNA */
  558. #define AF_DECnet       12              /* DECnet */
  559. #define AF_DLI          13              /* Direct data link interface */
  560. #define AF_LAT          14              /* LAT */
  561. #define AF_HYLINK       15              /* NSC Hyperchannel */
  562. #define AF_APPLETALK    16              /* AppleTalk */
  563. #define AF_NETBIOS      17              /* NetBios-style addresses */
  564.  
  565. #define AF_MAX          18
  566.  
  567.  
  568. #ifndef RC_INVOKED
  569.  
  570. #ifndef __INSIDE_CYGWIN__
  571. /*
  572.  * Structure used by kernel to store most
  573.  * addresses.
  574.  */
  575. struct sockaddr {
  576.   u_short sa_family;
  577.   char    sa_data[14];
  578. };
  579. #endif /* ndef __INSIDE_CYGWIN__ */
  580.  
  581. /*
  582.  * Structure used by kernel to pass protocol
  583.  * information in raw sockets.
  584.  */
  585. struct sockproto {
  586.   u_short sp_family;
  587.   u_short sp_protocol;
  588. };
  589.  
  590. #endif    /* RC_INVOKED */
  591.  
  592.  
  593. /*
  594.  * Protocol families, same as address families for now.
  595.  */
  596. #define PF_UNSPEC       AF_UNSPEC
  597. #define PF_UNIX         AF_UNIX
  598. #define PF_INET         AF_INET
  599. #define PF_IMPLINK      AF_IMPLINK
  600. #define PF_PUP          AF_PUP
  601. #define PF_CHAOS        AF_CHAOS
  602. #define PF_NS           AF_NS
  603. #define PF_IPX          AF_IPX
  604. #define PF_ISO          AF_ISO
  605. #define PF_OSI          AF_OSI
  606. #define PF_ECMA         AF_ECMA
  607. #define PF_DATAKIT      AF_DATAKIT
  608. #define PF_CCITT        AF_CCITT
  609. #define PF_SNA          AF_SNA
  610. #define PF_DECnet       AF_DECnet
  611. #define PF_DLI          AF_DLI
  612. #define PF_LAT          AF_LAT
  613. #define PF_HYLINK       AF_HYLINK
  614. #define PF_APPLETALK    AF_APPLETALK
  615.  
  616. #define PF_MAX          AF_MAX
  617.  
  618.  
  619. #ifndef    RC_INVOKED
  620. #ifndef __INSIDE_CYGWIN__
  621. /*
  622.  * Structure used for manipulating linger option.
  623.  */
  624. struct  linger {
  625.   u_short l_onoff;
  626.   u_short l_linger;
  627. };
  628. #endif  /* ndef __INSIDE_CYGWIN__ */
  629. #endif    /* RC_INVOKED */
  630.  
  631. /*
  632.  * Level number for (get/set)sockopt() to apply to socket itself.
  633.  */
  634. #define SOL_SOCKET      0xffff          /* options for socket level */
  635.  
  636. /*
  637.  * Maximum queue length specifiable by listen.
  638.  */
  639. #define SOMAXCONN       5
  640.  
  641. #define MSG_OOB         0x1             /* process out-of-band data */
  642. #define MSG_PEEK        0x2             /* peek at incoming message */
  643. #define MSG_DONTROUTE   0x4             /* send without using routing tables */
  644.  
  645. #define MSG_MAXIOVLEN   16
  646.  
  647. #define    MSG_PARTIAL     0x8000          /* partial send or recv for message xport */
  648.  
  649. /*
  650.  * Define constant based on rfc883, used by gethostbyxxxx() calls.
  651.  */
  652. #define MAXGETHOSTSTRUCT        1024
  653. #ifndef MAXHOSTNAMELEN
  654. #define MAXHOSTNAMELEN          MAXGETHOSTSTRUCT
  655. #endif
  656.  
  657. /*
  658.  * Define flags to be used with the WSAAsyncSelect() call.
  659.  */
  660. #define FD_READ         0x01
  661. #define FD_WRITE        0x02
  662. #define FD_OOB          0x04
  663. #define FD_ACCEPT       0x08
  664. #define FD_CONNECT      0x10
  665. #define FD_CLOSE        0x20
  666.  
  667. /*
  668.  * All Windows Sockets error constants are biased by WSABASEERR from
  669.  * the "normal"
  670.  */
  671. #define WSABASEERR              10000
  672. /*
  673.  * Windows Sockets definitions of regular Microsoft C error constants
  674.  */
  675. #define WSAEINTR                (WSABASEERR+4)
  676. #define WSAEBADF                (WSABASEERR+9)
  677. #define WSAEACCES               (WSABASEERR+13)
  678. #define WSAEFAULT               (WSABASEERR+14)
  679. #define WSAEINVAL               (WSABASEERR+22)
  680. #define WSAEMFILE               (WSABASEERR+24)
  681.  
  682. /*
  683.  * Windows Sockets definitions of regular Berkeley error constants
  684.  */
  685. #define WSAEWOULDBLOCK          (WSABASEERR+35)
  686. #define WSAEINPROGRESS          (WSABASEERR+36)
  687. #define WSAEALREADY             (WSABASEERR+37)
  688. #define WSAENOTSOCK             (WSABASEERR+38)
  689. #define WSAEDESTADDRREQ         (WSABASEERR+39)
  690. #define WSAEMSGSIZE             (WSABASEERR+40)
  691. #define WSAEPROTOTYPE           (WSABASEERR+41)
  692. #define WSAENOPROTOOPT          (WSABASEERR+42)
  693. #define WSAEPROTONOSUPPORT      (WSABASEERR+43)
  694. #define WSAESOCKTNOSUPPORT      (WSABASEERR+44)
  695. #define WSAEOPNOTSUPP           (WSABASEERR+45)
  696. #define WSAEPFNOSUPPORT         (WSABASEERR+46)
  697. #define WSAEAFNOSUPPORT         (WSABASEERR+47)
  698. #define WSAEADDRINUSE           (WSABASEERR+48)
  699. #define WSAEADDRNOTAVAIL        (WSABASEERR+49)
  700. #define WSAENETDOWN             (WSABASEERR+50)
  701. #define WSAENETUNREACH          (WSABASEERR+51)
  702. #define WSAENETRESET            (WSABASEERR+52)
  703. #define WSAECONNABORTED         (WSABASEERR+53)
  704. #define WSAECONNRESET           (WSABASEERR+54)
  705. #define WSAENOBUFS              (WSABASEERR+55)
  706. #define WSAEISCONN              (WSABASEERR+56)
  707. #define WSAENOTCONN             (WSABASEERR+57)
  708. #define WSAESHUTDOWN            (WSABASEERR+58)
  709. #define WSAETOOMANYREFS         (WSABASEERR+59)
  710. #define WSAETIMEDOUT            (WSABASEERR+60)
  711. #define WSAECONNREFUSED         (WSABASEERR+61)
  712. #define WSAELOOP                (WSABASEERR+62)
  713. #define WSAENAMETOOLONG         (WSABASEERR+63)
  714. #define WSAEHOSTDOWN            (WSABASEERR+64)
  715. #define WSAEHOSTUNREACH         (WSABASEERR+65)
  716. #define WSAENOTEMPTY            (WSABASEERR+66)
  717. #define WSAEPROCLIM             (WSABASEERR+67)
  718. #define WSAEUSERS               (WSABASEERR+68)
  719. #define WSAEDQUOT               (WSABASEERR+69)
  720. #define WSAESTALE               (WSABASEERR+70)
  721. #define WSAEREMOTE              (WSABASEERR+71)
  722.  
  723. #define WSAEDISCON              (WSABASEERR+101)
  724.  
  725. /*
  726.  * Extended Windows Sockets error constant definitions
  727.  */
  728. #define WSASYSNOTREADY          (WSABASEERR+91)
  729. #define WSAVERNOTSUPPORTED      (WSABASEERR+92)
  730. #define WSANOTINITIALISED       (WSABASEERR+93)
  731.  
  732. /*
  733.  * Error return codes from gethostbyname() and gethostbyaddr()
  734.  * (when using the resolver). Note that these errors are
  735.  * retrieved via WSAGetLastError() and must therefore follow
  736.  * the rules for avoiding clashes with error numbers from
  737.  * specific implementations or language run-time systems.
  738.  * For this reason the codes are based at WSABASEERR+1001.
  739.  * Note also that [WSA]NO_ADDRESS is defined only for
  740.  * compatibility purposes.
  741.  */
  742.  
  743. #ifndef __INSIDE_CYGWIN__
  744. #define h_errno         WSAGetLastError()
  745. #endif
  746.  
  747. /* Authoritative Answer: Host not found */
  748. #define WSAHOST_NOT_FOUND       (WSABASEERR+1001)
  749. #ifndef __INSIDE_CYGWIN__
  750. #define HOST_NOT_FOUND          WSAHOST_NOT_FOUND
  751. #endif
  752.  
  753. /* Non-Authoritative: Host not found, or SERVERFAIL */
  754. #define WSATRY_AGAIN            (WSABASEERR+1002)
  755. #ifndef __INSIDE_CYGWIN__
  756. #define TRY_AGAIN               WSATRY_AGAIN
  757. #endif
  758.  
  759. /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  760. #define WSANO_RECOVERY          (WSABASEERR+1003)
  761. #ifndef __INSIDE_CYGWIN__
  762. #define NO_RECOVERY             WSANO_RECOVERY
  763. #endif
  764.  
  765. /* Valid name, no data record of requested type */
  766. #define WSANO_DATA              (WSABASEERR+1004)
  767. #ifndef __INSIDE_CYGWIN__
  768. #define NO_DATA                 WSANO_DATA
  769. #endif
  770.  
  771. /* no address, look for MX record */
  772. #define WSANO_ADDRESS           WSANO_DATA
  773. #ifndef __INSIDE_CYGWIN__
  774. #define NO_ADDRESS              WSANO_ADDRESS
  775. #endif
  776.  
  777. /*
  778.  * Windows Sockets errors redefined as regular Berkeley error constants.
  779.  * These are commented out in Windows NT to avoid conflicts with errno.h.
  780.  * Use the WSA constants instead.
  781.  */
  782. #if 0
  783. #define EWOULDBLOCK             WSAEWOULDBLOCK
  784. #define EINPROGRESS             WSAEINPROGRESS
  785. #define EALREADY                WSAEALREADY
  786. #define ENOTSOCK                WSAENOTSOCK
  787. #define EDESTADDRREQ            WSAEDESTADDRREQ
  788. #define EMSGSIZE                WSAEMSGSIZE
  789. #define EPROTOTYPE              WSAEPROTOTYPE
  790. #define ENOPROTOOPT             WSAENOPROTOOPT
  791. #define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
  792. #define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
  793. #define EOPNOTSUPP              WSAEOPNOTSUPP
  794. #define EPFNOSUPPORT            WSAEPFNOSUPPORT
  795. #define EAFNOSUPPORT            WSAEAFNOSUPPORT
  796. #define EADDRINUSE              WSAEADDRINUSE
  797. #define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
  798. #define ENETDOWN                WSAENETDOWN
  799. #define ENETUNREACH             WSAENETUNREACH
  800. #define ENETRESET               WSAENETRESET
  801. #define ECONNABORTED            WSAECONNABORTED
  802. #define ECONNRESET              WSAECONNRESET
  803. #define ENOBUFS                 WSAENOBUFS
  804. #define EISCONN                 WSAEISCONN
  805. #define ENOTCONN                WSAENOTCONN
  806. #define ESHUTDOWN               WSAESHUTDOWN
  807. #define ETOOMANYREFS            WSAETOOMANYREFS
  808. #define ETIMEDOUT               WSAETIMEDOUT
  809. #define ECONNREFUSED            WSAECONNREFUSED
  810. #define ELOOP                   WSAELOOP
  811. #define ENAMETOOLONG            WSAENAMETOOLONG
  812. #define EHOSTDOWN               WSAEHOSTDOWN
  813. #define EHOSTUNREACH            WSAEHOSTUNREACH
  814. #define ENOTEMPTY               WSAENOTEMPTY
  815. #define EPROCLIM                WSAEPROCLIM
  816. #define EUSERS                  WSAEUSERS
  817. #define EDQUOT                  WSAEDQUOT
  818. #define ESTALE                  WSAESTALE
  819. #define EREMOTE                 WSAEREMOTE
  820. #endif
  821.  
  822. /* Socket function prototypes */
  823.  
  824. #ifndef    RC_INVOKED
  825.  
  826. SOCKET PASCAL accept (SOCKET s, struct sockaddr *addr,
  827.                           int *addrlen);
  828.  
  829. int PASCAL bind (SOCKET s, const struct sockaddr *addr, int namelen);
  830.  
  831. int PASCAL closesocket (SOCKET s);
  832.  
  833. int PASCAL connect (SOCKET s, const struct sockaddr *name, int namelen);
  834.  
  835. int PASCAL ioctlsocket (SOCKET s, long cmd, u_long *argp);
  836.  
  837. int PASCAL getpeername (SOCKET s, struct sockaddr *name,
  838.                             int * namelen);
  839.  
  840. int PASCAL getsockname (SOCKET s, struct sockaddr *name,
  841.                             int * namelen);
  842.  
  843. int PASCAL getsockopt (SOCKET s, int level, int optname,
  844.                            char * optval, int *optlen);
  845.  
  846. #ifndef __INSIDE_CYGWIN__
  847. u_long PASCAL htonl (u_long hostlong);
  848.  
  849. /* For some reason WSOCK.LIB has htons defined as a 4 byte paramter?! */
  850. #ifdef _WIN32
  851. u_short PASCAL htons (u_long hostshort);
  852. #else
  853. u_short PASCAL htons (u_short hostshort);
  854. #endif /* _WIN32 */
  855. #endif /* ndef __INSIDE_CYGWIN__ */
  856.  
  857. unsigned long PASCAL inet_addr (const char * cp);
  858.  
  859. char * inet_ntoa (struct in_addr in) PASCAL;
  860.  
  861. int PASCAL listen (SOCKET s, int backlog);
  862.  
  863. #ifndef __INSIDE_CYGWIN__
  864. u_long PASCAL ntohl (u_long netlong);
  865.  
  866. /* For some reason WSOCK.LIB has ntohs defined as a 4 byte paramter?! */
  867. #ifdef _WIN32
  868. u_short PASCAL ntohs (u_long netshort);
  869. #else
  870. u_short PASCAL ntohs (u_short netshort);
  871. #endif /* _WIN32 */
  872. #endif /* ndef __INSIDE_CYGWIN__ */
  873.  
  874. int PASCAL recv (SOCKET s, char * buf, int len, int flags);
  875.  
  876. int PASCAL recvfrom (SOCKET s, char * buf, int len, int flags,
  877.                          struct sockaddr *from, int * fromlen);
  878.  
  879. #ifndef __INSIDE_CYGWIN__
  880. int PASCAL select (int nfds, fd_set *readfds, fd_set *writefds,
  881.                        fd_set *exceptfds, const struct timeval *timeout);
  882. #endif /* ndef __INSIDE_CYGWIN__ */
  883.  
  884. int PASCAL send (SOCKET s, const char * buf, int len, int flags);
  885.  
  886. int PASCAL sendto (SOCKET s, const char * buf, int len, int flags,
  887.                        const struct sockaddr *to, int tolen);
  888.  
  889. int PASCAL setsockopt (SOCKET s, int level, int optname,
  890.                            const char * optval, int optlen);
  891.  
  892. int PASCAL shutdown (SOCKET s, int how);
  893.  
  894. SOCKET PASCAL socket (int af, int type, int protocol);
  895.  
  896. /* Database function prototypes */
  897.  
  898. PASCAL struct hostent * gethostbyaddr(const char * addr,
  899.                                               int len, int type);
  900.  
  901. PASCAL struct hostent * gethostbyname(const char * name);
  902.  
  903. #ifndef __INSIDE_CYGWIN__
  904. int PASCAL gethostname (char * name, int namelen);
  905. #endif /* ndef __INSIDE_CYGWIN__ */
  906.  
  907. PASCAL struct servent * getservbyport(int port, const char * proto);
  908.  
  909. PASCAL struct servent * getservbyname(const char * name,
  910.                                               const char * proto);
  911.  
  912. PASCAL struct protoent * getprotobynumber(int proto);
  913.  
  914. PASCAL struct protoent * getprotobyname(const char * name);
  915.  
  916. /* Microsoft Windows Extension function prototypes */
  917.  
  918. /* int PASCAL WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData); */
  919. int PASCAL WSAStartup(int wVersionRequired, LPWSADATA lpWSAData);
  920.  
  921.  
  922. int PASCAL WSACleanup(void);
  923.  
  924. void PASCAL WSASetLastError(int iError);
  925.  
  926. int PASCAL WSAGetLastError(void);
  927.  
  928. WINBOOL PASCAL WSAIsBlocking(void);
  929.  
  930. int PASCAL WSAUnhookBlockingHook(void);
  931.  
  932. FARPROC PASCAL WSASetBlockingHook(FARPROC lpBlockFunc);
  933.  
  934. int PASCAL WSACancelBlockingCall(void);
  935.  
  936. HANDLE PASCAL WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
  937.                                         const char * name, 
  938.                                         const char * proto,
  939.                                         char * buf, int buflen);
  940.  
  941. HANDLE PASCAL WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
  942.                                         const char * proto, char * buf,
  943.                                         int buflen);
  944.  
  945. HANDLE PASCAL WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
  946.                                          const char * name, char * buf,
  947.                                          int buflen);
  948.  
  949. HANDLE PASCAL WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
  950.                                            int number, char * buf,
  951.                                            int buflen);
  952.  
  953. HANDLE PASCAL WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
  954.                                         const char * name, char * buf,
  955.                                         int buflen);
  956.  
  957. HANDLE PASCAL WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
  958.                                         const char * addr, int len, int type,
  959.                                         char * buf, int buflen);
  960.  
  961. int PASCAL WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
  962.  
  963. int PASCAL WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
  964.                                long lEvent);
  965.  
  966. int PASCAL WSARecvEx (SOCKET s, char * buf, int len, int *flags);
  967.  
  968. /* Microsoft Windows Extended data types */
  969. typedef struct sockaddr SOCKADDR;
  970. typedef struct sockaddr *PSOCKADDR;
  971. typedef struct sockaddr *LPSOCKADDR;
  972.  
  973. typedef struct sockaddr_in SOCKADDR_IN;
  974. typedef struct sockaddr_in *PSOCKADDR_IN;
  975. typedef struct sockaddr_in *LPSOCKADDR_IN;
  976.  
  977. typedef struct linger LINGER;
  978. typedef struct linger *PLINGER;
  979. typedef struct linger *LPLINGER;
  980.  
  981. typedef struct in_addr IN_ADDR;
  982. typedef struct in_addr *PIN_ADDR;
  983. typedef struct in_addr *LPIN_ADDR;
  984.  
  985. typedef struct fd_set FD_SET;
  986. typedef struct fd_set *PFD_SET;
  987. typedef struct fd_set *LPFD_SET;
  988.  
  989. typedef struct hostent HOSTENT;
  990. typedef struct hostent *PHOSTENT;
  991. typedef struct hostent *LPHOSTENT;
  992.  
  993. typedef struct servent SERVENT;
  994. typedef struct servent *PSERVENT;
  995. typedef struct servent *LPSERVENT;
  996.  
  997. typedef struct protoent PROTOENT;
  998. typedef struct protoent *PPROTOENT;
  999. typedef struct protoent *LPPROTOENT;
  1000.  
  1001. typedef struct timeval TIMEVAL;
  1002. typedef struct timeval *PTIMEVAL;
  1003. typedef struct timeval *LPTIMEVAL;
  1004.  
  1005. #endif    /* RC_INVOKED */
  1006.  
  1007. /*
  1008.  * Windows message parameter composition and decomposition
  1009.  * macros.
  1010.  *
  1011.  * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
  1012.  * when constructing the response to a WSAAsyncGetXByY() routine.
  1013.  */
  1014. #define WSAMAKEASYNCREPLY(buflen,error)     MAKELONG(buflen,error)
  1015. /*
  1016.  * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
  1017.  * when constructing the response to WSAAsyncSelect().
  1018.  */
  1019. #define WSAMAKESELECTREPLY(event,error)     MAKELONG(event,error)
  1020. /*
  1021.  * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
  1022.  * to extract the buffer length from the lParam in the response
  1023.  * to a WSAGetXByY().
  1024.  */
  1025. #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  1026. /*
  1027.  * WSAGETASYNCERROR is intended for use by the Windows Sockets application
  1028.  * to extract the error code from the lParam in the response
  1029.  * to a WSAGetXByY().
  1030.  */
  1031. #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  1032. /*
  1033.  * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
  1034.  * to extract the event code from the lParam in the response
  1035.  * to a WSAAsyncSelect().
  1036.  */
  1037. #define WSAGETSELECTEVENT(lParam)           LOWORD(lParam)
  1038. /*
  1039.  * WSAGETSELECTERROR is intended for use by the Windows Sockets application
  1040.  * to extract the error code from the lParam in the response
  1041.  * to a WSAAsyncSelect().
  1042.  */
  1043. #define WSAGETSELECTERROR(lParam)           HIWORD(lParam)
  1044.  
  1045. #ifdef __cplusplus
  1046. }
  1047. #endif /* __cplusplus */
  1048.  
  1049. #endif /* _GNU_H_WINDOWS32_SOCKETS */
  1050.